<template>
	<view>
		<u-navbar title="添加">
			<view style="display: flex; justify-content: flex-end; width: 100%;">
				<view style="margin-right: 30rpx;">发布</view>
			</view>
		</u-navbar>
		
		<view style="display: flex; flex-direction: column; align-items: center;">
			<view style="width: 680rpx;">
				<u-input  placeholder="为你的球场起个名字吧~" />
			</view>
		</view>
		<u-line color="#c1c1c1" border-style="solid" direction="row"></u-line>
		<view style="display: flex; flex-direction: column; align-items: center;">
			<view style="width: 680rpx; height: 300rpx;">
				<u-input type="textarea"  placeholder="介绍一下你的球场~" />
			</view>
		</view>
		<view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
				 <image :src="imgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="ChooseImage" v-if="imgList.length<9">
					<text class='cuIcon-cameraadd'></text>
				</view>
			</view>
		</view>
		<u-line color="#c1c1c1" border-style="solid" direction="row"></u-line>
		<view style="display: flex; flex-direction: column; align-items: center;">
			<view style="width: 680rpx; height: 80rpx; display: flex; align-items: center;">
				<text class="cuIcon-location"></text>
				<text style="padding-left: 5rpx; font-size: 26rpx; color: #909399;">添加地点</text>
			</view>
		</view>
		<u-line color="#c1c1c1" border-style="solid" direction="row"></u-line>

		
	</view>
</template>


<script>
	export default {
		data() {
			return {
				index:-1,
				imgList:[]
			}
		},
		methods: {
			ChooseImage() {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.imgList = res.tempFilePaths
						}
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '提示',
					content: '确定要删除这个吗？',
					cancelText: '取消',
					confirmText: '删除',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
		}
	}
</script>

<style>

</style>
